import request from "@/utils/request.js";

const Api = {
    create: "/v1/data/custom",
    export: "/v1/data/custom/export",
    delete: "/v1/data/custom/",
    batchDelete: "/v1/data/custom/batch/del",
    update: "/v1/data/custom/",
    getList: "/v1/data/custom",
    getTableList: "/v1/data/custom/table/meter",
    getObj: "/v1/data/custom/",
}

/**
 * 创建数据字段
 */
export const create_field = (data) => {
    return request({
        url: Api.create,
        method: "POST",
        data,
    });
};

/**
 * 导入数据字段
 */
export const export_field = (data) => {
    return request({
        url: Api.export,
        method: "POST",
        headers: {
            "Content-Type": "multipart/form-data",
        },
        data,
    });
};

/**
 * 删除数据字段
 */
export const delete_field = (id) => {
    return request({
        url: Api.delete + id,
        method: "DELETE",
    });
};

/**
 * 批量删除数据字段
 */
export const batch_delete_field = (ids) => {
    return request({
        url: Api.batchDelete,
        method: "DELETE",
        data: ids,
    });
};

/**
 * 更新数据字段
 */
export const update_field = (id, data) => {
    return request({
        url: Api.update + id,
        method: "PUT",
        data,
    });
};

/**
 * 获取分页数据字段列表
 */
export const get_field_list = (params) => {
    return request({
        url: Api.getList,
        method: "GET",
        params,
    });
};

/**
 * 获取数据字段表格列
 */
export const get_table_field_list = (params) => {
    return request({
        url: Api.getTableList,
        method: "GET",
        params,
    });
};

/**
 * 获取数据字段
 */
export const get_field_obj = (id) => {
    return request({
        url: Api.getObj + id,
        method: "GET",
    });
};
